package leftMain;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class MessageBox extends JDialog implements MouseListener
{
	private JLabel labelField;
	private JTextField textField;
	
	private JLabel labelType;
	private JComboBox comboType;
	
	private JButton okButton;
	private JButton cancelButton;
	
	
	public MessageBox(int x, int y)
	{
		//Frame
		this.setSize(200, 200);
		this.setLayout(null);
		this.setAlwaysOnTop(true);
		this.setModal(true);
		setBounds((x+100), (y+100), 400, 270);
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				dispose();
				//System.exit(0);
			}
		});
		
		labelField = new JLabel("File name:");
		textField = new JTextField();
		
		okButton = new JButton("Ok");
		cancelButton = new JButton("Cancel");
		
		labelType = new JLabel("Save as type:");
		comboType = new JComboBox();
		
		labelField.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		labelField.setBounds(5, 12, 100, 25);
		textField.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		textField.setBounds(135, 10, 250, 25);
		
		labelType.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		labelType.setBounds(5, 39, 150, 25);
		comboType.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		comboType.setBounds(135, 37, 249, 25);
		comboType.addItem("Please Choose . . .");
		comboType.addItem("Word (.doc)");
		comboType.addItem("Text Document (.txt)");
		
		//Ok Button
		okButton.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		okButton.setBounds(135, 70, 123, 25);
		okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonItemActionPerformed(evt);
            }
        });
		
		//Cancel Button
		cancelButton.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		cancelButton.setBounds(261, 70, 123, 25);
		cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonItemActionPerformed(evt);
            }
        });
		
		//Frame (cont....)
		this.getContentPane().add(labelField);
		this.getContentPane().add(textField);
		this.getContentPane().add(labelType);
		this.getContentPane().add(comboType);
		this.getContentPane().add(okButton);
		this.getContentPane().add(cancelButton);
		this.setVisible(true);
		this.repaint();
		
	}
	
	private void okButtonItemActionPerformed(java.awt.event.ActionEvent evt)
	{
		if(textField.getText().equals(""))
		{
			javax.swing.JOptionPane.showMessageDialog(this, "Invalid file name", "Error!", javax.swing.JOptionPane.OK_OPTION);
		}
		else
		{
			
		}
		
	}
	
	private void cancelButtonItemActionPerformed(java.awt.event.ActionEvent evt)
	{
		this.dispose();
	}
	
	public void mouseClicked(MouseEvent e)
	{

	}
	
	public void mouseEntered(MouseEvent e)
	{
		
	}
	
	public void mouseExited(MouseEvent e)
	{
		
	}
	
	public void mousePressed(MouseEvent e)
	{

	}
	
	public void mouseReleased(MouseEvent e)
	{
		
	}
	
	public void save(String filename)
	{	
		try
		{
			File outputFile = new File("C:/" + filename);
			PrintWriter out = new PrintWriter(new FileWriter(outputFile));
			
			//message?
			
			out.close();
		}
		catch (IOException ex1)
		{
      		System.err.println("IO Exception (main): " + ex1.getMessage());
      		javax.swing.JOptionPane.showMessageDialog(this, "Invalid file name", "Error!", javax.swing.JOptionPane.OK_OPTION);
       	}	
	}
	
}